import { memo } from "react";
import DataDisplay_content from "../../baseUI/dataDisplay_content/idnex";
import { useNavigate, useSearchParams } from "react-router-dom";
import OrderStyle from "./style";
import { useGetOrganizationInfo } from "../../service/organization";
import { PRICE_ICON } from "../../constant";
import { CloseOutline, ReceivePaymentOutline } from "antd-mobile-icons";
import { useGetUserInfo } from "../../service/user";
import Hr from "../../baseUI/hr";
import { routeItmeType } from "../../router";

const Order = memo(() => {
  const [searchParams] = useSearchParams();
  const { data: userInfo } = useGetUserInfo();
  const nav = useNavigate();
  const { orgId, buyNum, price, productId, productName, orderCode } =
    Object.fromEntries(searchParams);
  const { data } = useGetOrganizationInfo(orgId);
  console.log(userInfo);
  return (
    <OrderStyle>
      <DataDisplay_content
        loading={false}
        title="订单信息"
        returnClick={() => {
          nav(`/${routeItmeType.PRODUCT_DETAIL}/${productId}`);
        }}
      >
        <div className="curtain">
          <div className="curtain_icon">
            <ReceivePaymentOutline />
          </div>
          <div className="curtain_title">支付成功</div>
          <div className="curtain_price">{PRICE_ICON + price}</div>
        </div>
        <div className="info">
          <div className="orderCode info_item">
            <div className="title">订单编号</div>
            <div className="element">{orderCode}</div>
          </div>
          <Hr />
          <div className="product info_item">
            <div className="title">商品详情</div>
            <div className="element">
              {productName} <CloseOutline /> {buyNum}
            </div>
          </div>
          <Hr />
          <div className="org info_item">
            <div className="title">所属门店</div>
            <div className="element">{data?.name}</div>
          </div>
          <Hr />
          <div className="byUser info_item">
            <div className="title">收货人</div>
            <div className="element">{userInfo?.name === "" ? "淡云教育用户" + userInfo?.id : userInfo?.name}</div>
          </div>
        </div>
      </DataDisplay_content>
    </OrderStyle>
  );
});

export default Order;
